/*******************************************************
 * @Title: GyroGuideKiwiView.java
 * @Package org.shangjiyu.gyroguide.KiwiView
 * @Description: TODO(用一句话描述该文件做什么)
 * @author shangjiyu@gmail.com
 * @date 2014-2-14 下午4:33:31
 * @version V1.0
 ********************************************************/

package org.shangjiyu.gyroguide.KiwiView;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;

import com.kitware.KiwiViewer.KiwiGLSurfaceView;
import com.kitware.KiwiViewer.KiwiNative;
import com.kitware.KiwiViewer.KiwiViewerActivity;

/********************************************************
 * @ClassName: GyroGuideKiwiView
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author shangjiyu
 * @date 2014-2-14 下午4:33:31
 */

public class GyroGuideKiwiView extends KiwiGLSurfaceView {

	public static final String TAG = "GyroguideKiwiView";
	String viewTitle;
	/********************************************************
	 *Title: 
	 *Description: 
	 *@param context
	 */

	public GyroGuideKiwiView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	/********************************************************
	 *Title: 
	 *Description: 
	 *@param context
	 *@param attrs
	 */

	public GyroGuideKiwiView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}
	
	public void setTitle(String titleString) {
		this.viewTitle = titleString;
	}
	
	/********************************************************
	 *Title: loadDataset
	 *Description: 
	 * @param filename
	 * @param builtinDatasetIndex
	 * @param loader
	 * @see com.kitware.KiwiViewer.KiwiGLSurfaceView#loadDataset(java.lang.String, int, com.kitware.KiwiViewer.KiwiViewerActivity)
	 *********************************************************/
	
	@Override
	public void loadDataset(final  String filename, final int builtinDatasetIndex,
			final KiwiViewerActivity loader) {
		// TODO Auto-generated method stub
//		super.loadDataset(filename, builtinDatasetIndex, loader);
		queueEvent(new Runnable() {
	        public void run() {

	          Log.w(TAG, String.format("loadDataset %s %d", filename, builtinDatasetIndex));

	          final boolean result = KiwiNative.loadDataset(filename, builtinDatasetIndex);
	          final String errorTitle = KiwiNative.getLoadDatasetErrorTitle();
	          final String errorMessage = KiwiNative.getLoadDatasetErrorMessage();

	          requestRender();

	          GyroGuideKiwiView.this.post(new Runnable() {
	            public void run() {
	              loader.postLoadDataset(filename, result, errorTitle, errorMessage);
	            }});
	        }});
	}
}

